CFLAGS = -fpic -coverage -lm -std=c99

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

runtests: testDrawCard 
	./testDrawCard &> unittestresult.out
	gcov dominion.c >> unittestresult.out
	cat dominion.c.gcov >> unittestresult.out

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

unittestresults.out: unittest1.c unittest2.c unittest3.c unittest4.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c dominion.o rngs.o
	echo "Result for running unit tests:" > unittestresult.out

	echo "unittest1.c:" >> unittestresult.out
	gcc -o unittest1 unittest1.c -Wall $(CFLAGS)
	./unittest1 >> unittestresult.out
	gcov unittest1.c >> unittestresult.out

	echo "unittest2.c:" >> unittestresult.out
	gcc -o unittest2 -g unittest2.c dominion.o rngs.o -Wall $(CFLAGS)
	./unittest2 >> unittestresult.out
	gcov unittest2.c >> unittestresult.out

	echo "unittest3.c:" >> unittestresult.out
	gcc -o unittest3 -g unittest3.c dominion.o rngs.o -Wall $(CFLAGS)
	./unittest3 >> unittestresult.out
	gcov unittest3.c >> unittestresult.out

	echo "unittest4.c:" >> unittestresult.out
	gcc -o unittest4 -g unittest4.c dominion.o rngs.o -Wall $(CFLAGS)
	./unittest4 >> unittestresult.out
	gcov unittest4.c >> unittestresult.out

	echo "cardtest1.c:" >> unittestresult.out
	gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest1 >> unittestresult.out
	gcov cardtest1.c >> unittestresult.out

	echo "cardtest2.c:" >> unittestresult.out
	gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest2 >> unittestresult.out
	gcov cardtest2.c >> unittestresult.out

	echo "cardtest3.c:" >> unittestresult.out
	gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest3 >> unittestresult.out
	gcov cardtest3.c >> unittestresult.out

	echo "cardtest4.c:" >> unittestresult.out
	gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest4 >> unittestresult.out
	gcov cardtest4.c >> unittestresult.out

randomtestcard.out: randomtestcard.c dominion.o rngs.o
	echo "Result for running random test card:\n" > randomtestcard.out

	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o -Wall $(CFLAGS)
	./randomtestcard >> randomtestcard.out
	echo "\nResult for running dominion coverage:\n" >> randomtestcard.out
	gcov -b -f dominion.o >> randomtestcard.out

randomtestadventurer.out: randomtestadventurer.c dominion.o rngs.o
	echo "Result for running random test adventurer:\n" > randomtestadventurer.out

	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o -Wall $(CFLAGS)
	./randomtestadventurer >> randomtestadventurer.out
	echo "\nResult for running dominion coverage:\n" >> randomtestadventurer.out
	gcov -b -f dominion.o >> randomtestadventurer.out

cardtestresults.out: cardtest1.c cardtest2.c cardtest3.c cardtest4.c randomtestcard.c randomtestadventurer.c dominion.o rngs.o
	echo "Result for running card tests:" > cardtestresult.out

	echo "cardtest1.c:" >> cardtestresult.out
	gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest1 >> cardtestresult.out

	echo "cardtest2.c:" >> cardtestresult.out
	gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest2 >> cardtestresult.out

	echo "cardtest3.c:" >> cardtestresult.out
	gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest3 >> cardtestresult.out

	echo "cardtest4.c:" >> cardtestresult.out
	gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o -Wall $(CFLAGS)
	./cardtest4 >> cardtestresult.out

	echo "randomtestcard.c:" >> cardtestresult.out
	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o -Wall $(CFLAGS)
	./randomtestcard >> cardtestresult.out

	echo "randomtestadventurer.c:" >> cardtestresult.out
	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o -Wall $(CFLAGS)
	./randomtestadventurer >> cardtestresult.out

	echo "\nResult for running dominion coverage:\n" >> cardtestresult.out
	gcov -b -f dominion.o >> cardtestresult.out

all: playdom player testDrawCard testBuyCard badTestDrawCard

clean:
	rm -f *.o playdom.exe playdom test.exe test player player.exe testInit testInit.exe badTestDrawCard testDrawCard *.gcov *.gcda *.gcno *.so
	rm -f *.out unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestcard randomtestadventurer *~ *#